package com.ruihu.admin.module.business.node.config.domain.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruihu.admin.common.domain.BaseEntity;
import com.ruihu.admin.module.business.node.config.domain.dto.TaskProcessConfigAddDTO;
import com.ruihu.admin.module.business.node.config.domain.dto.TaskProcessConfigDTO;
import com.ruihu.admin.module.business.node.config.domain.dto.TaskProcessConfigUpdateDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Objects;

/**
 * [ 节点配置表 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2023-01-02 16:31:04
 * @since JDK1.8
 */

@Data
@TableName("t_task_process_config")
public class TaskProcessConfigEntity extends BaseEntity {


    /**
     * 配置名称
     */
    private String name;

    /**
     * 创建人
     */
    private Long creator;

    /**
     * 更新人
     */
    private Long updater;

    /**
     * 值类型 1:输入值; 2:下拉框
     */
    private Integer type;

    /**
     * 是否有异常描述 0否 1是
     */
    private Integer isThrowDesc;

    /**
     * 是否有图片 0否 1是
     */
    private Integer hasImage;

    /**
     * 接口获取照片 0否 1是
     */
    private Integer interfaceImage;

    /**
     * 是否固定元素 0 否 1 是
     */
    private Integer fixed;

    /**
     * 是否有其他 0 否 1 是
     */
    private Integer isOther;

    /**
     * 任务节点ID
     */
    private Long taskNodeId;

    /**
     * 单位
     */
    private String unit;

    /**
     * 删除标记
     */
    private Integer isDelete;

    public static TaskProcessConfigEntity convertToTaskProcessConfigEntity(TaskProcessConfigAddDTO addDTO) {
        if (addDTO == null) {
            return null;
        }

        TaskProcessConfigEntity entity = new TaskProcessConfigEntity();
        entity.setName(addDTO.getName());
        entity.setCreator(addDTO.getCreator());
        entity.setUpdater(addDTO.getUpdater());
        entity.setType(addDTO.getType());
        entity.setIsThrowDesc(addDTO.getIsThrowDesc());
        entity.setHasImage(addDTO.getHasImage());
        entity.setInterfaceImage(addDTO.getInterfaceImage());
        entity.setFixed(addDTO.getFixed());
        entity.setTaskNodeId(addDTO.getTaskNodeId());
        entity.setUnit(addDTO.getUnit());
        entity.setIsOther(addDTO.getIsOther());
        return entity;
    }


    public static TaskProcessConfigEntity convertToTaskProcessConfigEntity(TaskProcessConfigUpdateDTO updateDTO) {
        if (updateDTO == null) {
            return null;
        }

        TaskProcessConfigEntity entity = new TaskProcessConfigEntity();
        entity.setId(updateDTO.getId());
        entity.setName(updateDTO.getName());
        entity.setType(updateDTO.getType());
        entity.setUnit(StrUtil.isNotEmpty(updateDTO.getUnit()) ? updateDTO.getUnit() : null);
        entity.setIsThrowDesc(updateDTO.getIsThrowDesc());
        entity.setHasImage(updateDTO.getHasImage());
        entity.setInterfaceImage(updateDTO.getInterfaceImage());
        entity.setFixed(updateDTO.getFixed());
        entity.setTaskNodeId(updateDTO.getTaskNodeId());
        entity.setIsOther(updateDTO.getIsOther());
        return entity;
    }

    public static TaskProcessConfigEntity convertToTaskProcessConfigEntity(TaskProcessConfigDTO dto) {
        if (dto == null) {
            return null;
        }

        TaskProcessConfigEntity entity = new TaskProcessConfigEntity();
        entity.setId(dto.getId());
        entity.setName(dto.getName());
        entity.setCreateTime(dto.getCreateTime());
        entity.setUpdateTime(dto.getUpdateTime());
        entity.setCreator(dto.getCreator());
        entity.setUpdater(dto.getUpdater());
        entity.setType(dto.getType());
        entity.setIsThrowDesc(dto.getIsThrowDesc());
        entity.setUnit(dto.getUnit());
        entity.setHasImage(dto.getHasImage());
        entity.setInterfaceImage(dto.getInterfaceImage());
        entity.setFixed(dto.getFixed());
        entity.setTaskNodeId(dto.getNodeId());
        entity.setIsOther(dto.getIsOther());
        return entity;
    }

    public static TaskProcessConfigEntity copyIgnoreNullAndEmpty(TaskProcessConfigEntity sourceEntity, TaskProcessConfigEntity destEntity) {
        if (Objects.isNull(sourceEntity))
            return destEntity;
        if (Objects.nonNull(sourceEntity.getId())) {
            destEntity.setId(sourceEntity.getId());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getName())) {
            destEntity.setName(sourceEntity.getName());
        }
        if (Objects.nonNull(sourceEntity.getCreateTime())) {
            destEntity.setCreateTime(sourceEntity.getCreateTime());
        }
        if (Objects.nonNull(sourceEntity.getUpdateTime())) {
            destEntity.setUpdateTime(sourceEntity.getUpdateTime());
        }
        if (Objects.nonNull(sourceEntity.getCreator())) {
            destEntity.setCreator(sourceEntity.getCreator());
        }
        if (Objects.nonNull(sourceEntity.getUpdater())) {
            destEntity.setUpdater(sourceEntity.getUpdater());
        }
        if (Objects.nonNull(sourceEntity.getType())) {
            destEntity.setType(sourceEntity.getType());
        }
        if (Objects.nonNull(sourceEntity.getIsThrowDesc())) {
            destEntity.setIsThrowDesc(sourceEntity.getIsThrowDesc());
        }
        if (Objects.nonNull(sourceEntity.getHasImage())) {
            destEntity.setHasImage(sourceEntity.getHasImage());
        }
        if (Objects.nonNull(sourceEntity.getFixed())) {
            destEntity.setFixed(sourceEntity.getFixed());
        }
        if (Objects.nonNull(sourceEntity.getUnit())) {
            destEntity.setUnit(sourceEntity.getUnit());
        }
        if (Objects.nonNull(sourceEntity.getIsOther())) {
            destEntity.setIsOther(sourceEntity.getIsOther());
        }
        if (Objects.nonNull(sourceEntity.getTaskNodeId())) {
            destEntity.setTaskNodeId(sourceEntity.getTaskNodeId());
        }
        return destEntity;
    }
}
